package com.xdap.init.controller;

import com.definesys.mpaas.common.http.Response;
import com.xdap.init.service.InitModelFeildService;
import com.xdap.init.service.InitPackageService;
import com.xdap.init.service.JudgeModelService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auth lishushu
 * @2023/4/7 11:26
 * @desc {用于校验}
 **/
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/df/judge")
@Slf4j
public class JudgeController {

    @Autowired
    private InitModelFeildService initModelFeildService;
    @Autowired
    private InitPackageService initPackageService;
    @Autowired
    private JudgeModelService judgeModelService;


    /**
     * @auth lishushu
     * @2023/4/17 9:15
     * @desc {生成controller、service、po层的数据}
     * @packageName 起始的文件名称
     **/
    @PostMapping("/createFile")
    public Response createFile(@RequestParam("filePath") String filePath, @RequestParam("packageName") String packageName) throws Exception {
        Response res = new Response();
        try {
            String result = initPackageService.InitPackageService(filePath, packageName);
            res.setData(result);
        } catch (Exception e) {
            log.error("初始化package报错:{}", e);
            res.setCode(Response.CODE_ERR);
            res.setMessage(e.getMessage());
        }
        return res;
    }
    @PostMapping("/judgePo")
    public Response judgePo(@RequestParam("filePath") String filePath) throws Exception {
        Response res = new Response();
        try {
            String result = judgeModelService.judgePo(filePath);
            res.setData(result);
        } catch (Exception e) {
            log.error("初始化package报错:{}", e);
            res.setCode(Response.CODE_ERR);
            res.setMessage(e.getMessage());
        }
        return res;
    }

    @PostMapping("/judgeModel")
    public Response judgeModel(@RequestParam("formId") String formId) throws Exception {
        Response res = new Response();
        try {
            String result = judgeModelService.judgeModel(formId);
            res.setData(result);
        } catch (Exception e) {
            log.error("初始化package报错:{}", e);
            res.setCode(Response.CODE_ERR);
            res.setMessage(e.getMessage());
        }
        return res;
    }


}
